package com.hugoo.sch;

import com.hugoo.core.Conf;
import com.hugoo.core.db.Call;
import com.hugoo.core.db.HSF;
import it.sauronsoftware.cron4j.Task;
import it.sauronsoftware.cron4j.TaskExecutionContext;
import java.sql.CallableStatement;
import java.sql.SQLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Lovelock.Chan
 */
public class ExecProc extends Task {

    private static final Log log = LogFactory.getLog(ExecProc.class);
    private String sid;

    public ExecProc(String sid) {
        this.sid = sid;
    }

    @Override
    public void execute(TaskExecutionContext tec) throws RuntimeException {
        final String proc = Conf.getBaseProp(sid, Conf.SCH._schs_exec_proc);
        final String dbl = Conf.getBaseProp(sid, Conf.SCH._schs_exec_dbl);
        try {
            HSF.call(dbl, new Call() {
                public void proc(CallableStatement cs, Log log) throws SQLException {
                    cs.execute();
                }

                public String procSql() {
                    return "call " + proc;
                }
            });
        } catch (Exception e) {
            log.warn("定时调度-->执行存储过程【" + proc + "】出现异常！", e);
        }
    }
}
